<script setup>
import { ref, defineEmits, nextTick } from 'vue'
const props = defineProps(['categoryList', 'categoryId'])
const emits = defineEmits(['confirmClick'])
const currentId = ref(props.categoryId)
const changeCurrentId = id => {
  emits('confirmClick', id)
  if(currentId.value) {
    currentId.value = id
  }
}
const updateCategory = id => {
  currentId.value = id
  console.log(currentId.value)
}

defineExpose({
  updateCategory
})
</script>

<template>
<div class="change-category">
  <yk-scrollbar ref="scrollbar" height="150px">
    <div class="change-category-content">
      <div class="item" :class="{'active': currentId == 1}" @click="changeCurrentId(1)" >未分类</div>
      <div v-for="(item, index) in props.categoryList" :key="index" class="item" :class="{'active': item.ID === currentId }" @click="changeCurrentId(item.ID)">{{ item.category_name }}</div>
    </div>
  </yk-scrollbar>
</div>
</template>

<style scoped lang='less'>
.change-category {
  width: 100%;
  .change-category-content {
    overflow: hidden;
    width:100%;

    .item {
      margin: 10px;
      padding: 10px;
      background: @bg-color-s;
      height:30px;
      border-radius: 800px;
      line-height: 10px;

      &:hover {
        cursor: pointer;
        background: @pcolor-4;
      }


      &.active{
        background: @pcolor-3;
      }
    }
  }
}


</style>